package org.qengine.controller;

import org.qengine.entity.ClassEntity;
import org.qengine.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassService classService;

    @RequestMapping("/getClass")
    public ClassEntity getClassByID(@RequestParam("classID") Long classID) {
         return classService.getClassByID(classID);
    }

    @RequestMapping("/updateClass")
    public ResponseEntity<ClassEntity> updateClass(@RequestBody ClassEntity classEntity) {
        ClassEntity insertedClassEntity = classService.updateClass(classEntity);
        return ResponseEntity.status(HttpStatus.CREATED).body(insertedClassEntity);
    }


    @RequestMapping("/deleteClass")
    public String deleteClass(@RequestParam("classID") Long classID) {
        int result = classService.deleteClass(classID);
        if(result >= 1) {
            return "删除成功";
        } else {
            return "删除失败";
        }
    }


    @RequestMapping("/getAllClass")
    public List<ClassEntity> getAllClass() {
        return classService.getAllClass();
    }

}
